------------------------------------------------------------
-- EasyTrinket Buttonfacade Support
--
-- Special thanks: XBug
-- From: http://bbs.game.mop.com/viewthread.php?tid=1644785&extra=page%3D1&page=16
------------------------------------------------------------

if not IsAddOnLoaded("ButtonFacade") or not LibStub then return end
local BF = LibStub("AceAddon-3.0"):GetAddon("ButtonFacade")
local LBF = LibStub("LibButtonFacade", true)
if not BF or not LBF then return end

------------------------------------------------------------



local L = EASYTRINKET_LOCALE; -- locale table

local ET = "EasyTrinket"
local BFET = BF:NewModule(ET) -- use ace3 hadle onload func

local db
local default = {
	Skin = "Blizzard",
	Gloss = 0,
	Backdrop = false,
	Colors = {},
}

local function SkinCallback(skin, gloss, backdrop, group, button, colors)
	if not group then return end
	db[group] = db[group] or {}
	db[group].Skin = skin
	db[group].Gloss = gloss
	db[group].Backdrop = backdrop
	db[group].Colors = colors
end

function SetupGroup(group, prefix, count)
	local etgroup = LBF:Group(ET, group)	
	for i = 1, count do
		local button = getglobal(prefix..i)
		if button then
			etgroup:AddButton(button)
		end
	end
	if not db[group] then db[group] = default end
	etgroup:Skin(db[group].Skin, db[group].Gloss, db[group].Backdrop, db[group].Colors)
end

-- onload init
function BFET:OnInitialize()
	-- handle db
	if not EasyTrinketDB then EasyTrinketDB = {} end
	if not EasyTrinketDB.buttonStyle then EasyTrinketDB.buttonStyle = {} end
	db = EasyTrinketDB.buttonStyle
	db = db
	
	-- register to ButtonFacade
	LBF:RegisterSkinCallback(ET, SkinCallback)
	SetupGroup(L["main buttons"], "EasyTrinket_Trinket", 2)
	SetupGroup(L["menu buttons"], "EasyTrinket_MenuTrinket", EASYTRINKET_MENUBUTTON_NUM)
end

